<?php
/*
    ainitramfs base script
    Copyright (C) Ambroz Bizjak, 2010

    This file is part of ainitramfs.

    ainitramfs is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2
    as published by the Free Software Foundation.

    ainitramfs is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

require_once("{$ai_dataroot}/scripts_common.php");

function base_install ()
{
    global $ai_root;
    global $ai_out;
    global $ai_kmoddir;
    global $ai_kmodroot;
    global $ai_dataroot;
    global $ai_kmods;
    global $ai_options;
    global $ai_toolchain;

    $dirs = array();

    $files = array(
       "/etc/terminfo/l/linux",
    );

    $symlinks = array();

    $binaries = array(
        "ip",
        "/bin/login",
        "/sbin/agetty",
        "/usr/bin/badvpn-ncd",
        "/usr/bin/stdbuf",
        "/usr/libexec/coreutils/libstdbuf.so",
        "/usr/bin/nbd-server",
        "/usr/bin/cpufreq-set",
        "/usr/bin/cpufreq-info",
        "pstree",
        "ps",
        "ping",
        "halt",
    );

    $kmods = array(
        "acpi-cpufreq",
        "cpufreq_ondemand",
    );

    $kmod_dirs = array(
        "kernel/drivers/net",
    );

    // invoke common
    ai_scripts_common($dirs, $files, $symlinks, $binaries, $kmod_dirs, $kmods);

    // copy init NCD script
    if (!copy(ai_join_paths($ai_dataroot, "scripts/nbd-server-init.ncd"), ai_join_paths($ai_out, "init.ncd"))) {
        ai_error("cannot copy init NCD script");
    }

    // copy init wrapper
    $initdest = ai_join_paths($ai_out, "init");
    if (!copy(ai_join_paths($ai_dataroot, "scripts/nbd-server-init.sh"), $initdest)) {
        ai_error("cannot copy init wrapper");
    }
    if (!chmod($initdest, 0755)) {
        ai_error("cannot chmod init wrapper");
    }
}

base_install();
